package com.spt.springbootzhsx.service.suggest.Get_MovieToMovie_2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class GetMTM_Mapper extends Mapper<LongWritable, Text, Text, NullWritable>{
    private StringBuffer sb = new StringBuffer();
    private Text outK = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] val=value.toString().split("\t");
        String[] line = val[1].split(",");

        //每个电影id两两相连
        for (String s : line) {
            for (String s1 : line) {
                sb.append(s).append("\t").append(s1);

                outK.set(sb.toString());
                context.write(outK, NullWritable.get());
                sb.setLength(0);
                outK.clear();
            }
        }
    }
}
